<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<a id="contextPath"
   th:href="${#httpServletRequest.getScheme()+'://'+#httpServletRequest.getServerName()+':'+#httpServletRequest.getServerPort()+#httpServletRequest.getContextPath()+'/'}"/>
</body>
<script>
    function getContextPath() {
        var contextPath = $('#contextPath').attr('href');
        return contextPath
    }
</script>
</html>